#include "libgit2_clone.h"
const char* clone_private_key = "C:/Users/14122/.ssh/id_rsa";
//const char* clone_repository = "git@gitee.com:lingoing/demo111.git";
libgit2_clone::libgit2_clone(QWidget* parent)
    : QWidget(parent)
{
}
int clone_cred_acquire_cb(git_cred** cred, const char* url, const char* username_from_url, unsigned int allowed_types, void* payload)
{

    git_cred_ssh_key_new(cred, username_from_url, nullptr, clone_private_key, nullptr);

    return 0;
}
int libgit2_clone::clone(const char* clone_path,const char* clone_repository)
{

    git_libgit2_init();

    git_repository* rep = nullptr;
    git_clone_options opt = GIT_CLONE_OPTIONS_INIT;

    int error = 0;

    //    opt.checkout_branch = "master";
    opt.fetch_opts.callbacks.credentials = clone_cred_acquire_cb;

    error = git_clone(&rep, clone_repository, clone_path, &opt);
    if (error < 0) {
        const git_error* e = giterr_last();
        std::cout << "Error: " << error << " / " << e->klass << " : " << e->message << std::endl;

        goto SHUTDOWN;
    }

SHUTDOWN:
    git_repository_free(rep);
    git_libgit2_shutdown();
    return 0;
}
